home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / graphics / icon_related / icontools-2.01 / im.c < prev    next >
C/C++ Source or Header  |  1995-12-22  |  19KB  |  627 lines

  1. /*                                                               -*- C -*-
  2.  *  IM.C
  3.  *
  4.  *  (c)Copyright 1995 by Tobias Ferber,  ukjg@rz.uni-karlsruhe.de
  5.  *
  6.  *  This file is part of the IconTools distribution
  7.  *
  8.  *  IconMaker is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published
  10.  *  by the Free Software Foundation; either version 1 of the License,
  11.  *  or (at your option) any later version.
  12.  *
  13.  *  IconMaker is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with this program; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include "version.h"
  24. static char versiontag[]= "$VER: $Id: im.c,v 1.6 1995/07/22 16:41:12 tf Exp $";
  25.  
  26. #include <intuition/intuition.h>
  27. #include <intuition/intuitionbase.h>
  28. #include <graphics/gfxbase.h>
  29. #include <workbench/workbench.h>
  30. #include <workbench/icon.h>
  31.  
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <stdarg.h>
  35. #include <stdio.h>
  36.  
  37. #include "iffp/ilbm.h"
  38. #include "iffp/ilbmapp.h"
  39.  
  40. #ifndef IFFPARSENAME
  41. #define IFFPARSENAME "iffparse.library"
  42. #endif
  43.  
  44. extern BOOL PutDiskObject(char *, struct DiskObject *);
  45.  
  46. void display_version_information(void)
  47. {
  48.   static char license[]=
  49.     "IconMaker is free software; you can redistribute it and/or modify\n"
  50.     "it under the terms of the GNU General Public License as published\n"
  51.     "by the Free Software Foundation; either version 1 of the License,\n"
  52.     "or (at your option) any later version.\n"
  53.     "\n"
  54.     "IconMaker is distributed in the hope that it will be useful,\n"
  55.     "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  56.     "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
  57.     "GNU General Public License for more details.\n"
  58.     "\n"
  59.     "You should have received a copy of the GNU General Public License\n"
  60.     "along with this program; see the file COPYING.  If not, write to the\n"
  61.     "Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
  62.     ;
  63.  
  64.   puts("\nIconMaker/IM Version " VERSION " (compiled " __DATE__ ", " __TIME__ ")\n"
  65.        "(c)Copyright 1995 by Tobias Ferber, ukjg@rz.uni-karlsruhe.de\n");
  66.  
  67.   puts(license);
  68. }
  69.  
  70. UWORD *ImageDataFromBitMap(struct BitMap *bm, WORD width, WORD height);
  71.  
  72. /* System */
  73.  
  74. struct Library *GfxBase      = NULL;
  75. struct Library *IFFParseBase = NULL;
  76. struct Library *IconBase     = NULL;
  77.  
  78. /*
  79.  *  These are the default values
  80.  */
  81.  
  82. static struct Image gr = { 0, 0, 0, 0, 0, NULL, 0, 0, NULL };  /* GadgetRender */
  83. static struct Image sr = { 0, 0, 0, 0, 0, NULL, 0, 0, NULL };  /* SelectRender */
  84.  
  85. static char *tt[] = { "FILETYPE=ILBM", NULL };
  86.  
  87. static struct DrawerData dd = {
  88.  { 60,                             /* dd_NewWindow.LeftEdge */
  89.    50,                             /* dd_NewWindow.TopEdge */
  90.    330,                            /* dd_NewWindow.Width */
  91.    140,                            /* dd_NewWindow.Height */
  92.    255,                            /* dd_NewWindow.DetailPen */
  93.    255,                            /* dd_NewWindow.BlockPen */
  94.    NULL,                           /* dd_NewWindow.IDCMPFlags */
  95.    WFLG_SIZEGADGET
  96.    | WFLG_DRAGBAR
  97.    | WFLG_DEPTHGADGET
  98.    | WFLG_CLOSEGADGET
  99.    | WFLG_SIZEBRIGHT
  100.    | WFLG_SIZEBBOTTOM
  101.    | WFLG_SIMPLE_REFRESH
  102.    | WFLG_REPORTMOUSE
  103.    | WFLG_ACTIVATE
  104.    | WFLG_NEWLOOKMENUS
  105.    | WFLG_WBENCHWINDOW,            /* dd_NewWindow.Flags */
  106.    NULL,                           /* dd_NewWindow.FirstGadget */
  107.    NULL,                           /* dd_NewWindow.CheckMark */
  108.    NULL,                           /* dd_NewWindow.Title */
  109.    NULL,                           /* dd_NewWindow.Screen */
  110.    NULL,                           /* dd_NewWindow.BitMap */
  111.    0,                              /* dd_NewWindow.MinWidth */
  112.    0,                              /* dd_NewWindow.MinHeight */
  113.    65535,                          /* dd_NewWindow.MaxWidth */
  114.    65535,                          /* dd_NewWindow.MaxHeight */
  115.    WBENCHSCREEN },                 /* dd_NewWindow.Type */
  116.    0,                              /* dd_CurrentX */
  117.    0,                              /* dd_CurrentY */
  118.    3,                              /* dd_Flags */
  119.    0,                              /* dd_ViewModes */
  120. };
  121.  
  122. static struct DiskObject icon = {
  123.    WB_DISKMAGIC,                   /* do_Magic */
  124.    WB_DISKVERSION,                 /* do_Version */
  125.  { NULL,                           /* do_Gadget.NextGadget */
  126.    0,                              /* do_Gadget.LeftEdge */
  127.    0,                              /* do_Gadget.TopEdge */
  128.    0,                              /* do_Gadget.Width */
  129.    0,                              /* do_Gadget.Height */
  130.    GFLG_GADGHIMAGE|GFLG_GADGIMAGE, /* do_Gadget.Flags */
  131.    GACT_RELVERIFY|GACT_IMMEDIATE,  /* do_Gadget.Activation */
  132.    GTYP_BOOLGADGET,                /* do_Gadget.GadgetType */
  133.    (APTR)&gr,                      /* do_Gadget.GadgetRender */
  134.    (APTR)&sr,                      /* do_Gadget.SelectRender */
  135.    NULL,                           /* do_Gadget.GadgetText */
  136.    0,                              /* do_Gadget.MutualExclude */
  137.    NULL,                           /* do_Gadget.SpecialInfo */
  138.    0,                              /* do_Gadget.GadgetID */
  139.    WB_DISKREVISION },              /* do_Gadget.UserData */
  140.    WBPROJECT,                      /* do_Type */
  141.    "MultiView",                    /* do_DefaultTool */
  142.    &tt[0],                         /* do_ToolTypes */
  143.    NO_ICON_POSITION,               /* do_CurrentX */
  144.    NO_ICON_POSITION,               /* do_CurrentY */
  145.    &dd,                            /* do_DrawerData */
  146.    NULL,                           /* do_ToolWindow */
  147.    8192,                           /* do_StackSize */
  148. };
  149.  
  150. /*
  151.  *  The global error function
  152.  */
  153.  
  154. static char *whoami;  /* global copy of argv[0] */
  155.  
  156. static void echo(const char *fmt, ...)
  157. {
  158.   va_list argp;
  159.   va_start(argp,fmt);
  160.  
  161.   fprintf(stderr,"%s: ",whoami);
  162.   vfprintf(stderr,(char *)fmt,argp);
  163.   fprintf(stderr,"\n");
  164.   fflush(stderr);
  165.  
  166.   va_end(argp);
  167. }
  168.  
  169. /*
  170.  *  Some top-level functions for ILBM loading
  171.  */
  172.  
  173. static struct ILBMInfo *myloadbrush(char *fname)
  174. {
  175.   int err= 0;
  176.  
  177.   struct ILBMInfo *ilbm= (struct ILBMInfo *)AllocVec( sizeof(struct ILBMInfo), MEMF_CLEAR );
  178.  
  179.   if(ilbm)
  180.   {
  181.     /* ILBM Property chunks to be grabbed - only BMHD needed for this app */
  182.     static LONG ilbmprops[] = { ID_ILBM, ID_BMHD, TAG_DONE };
  183.  
  184.     /* ILBM Collection chunks (more than one in file) to be gathered */
  185.     static LONG *ilbmcollects = NULL;  /* none needed for this app */
  186.  
  187.     /* ILBM Chunk to stop on */
  188.     static LONG ilbmstops[] = { ID_ILBM, ID_BODY, TAG_DONE };
  189.  
  190.     ilbm->ParseInfo.propchks    = ilbmprops;
  191.     ilbm->ParseInfo.collectchks = ilbmcollects;
  192.     ilbm->ParseInfo.stopchks    = ilbmstops;
  193.  
  194.     /* Alloc IFF handle for frame */
  195.  
  196.     if( (ilbm->ParseInfo.iff= AllocIFF()) )
  197.     {
  198.       if( (err= loadbrush(ilbm,fname)) )
  199.       {
  200.         /*fprintf(stderr,IFFerr(err));*/
  201.         echo("Can't load ILBM `%s'",fname);
  202.         ++err;
  203.       }
  204.     }
  205.     else /* !AllocIFF() */
  206.     {
  207.       echo("AllocIFF() failed -- not enough memory!?");
  208.       ++err;
  209.     }
  210.   }
  211.  
  212.   if(err && ilbm)
  213.   {
  214.     if(ilbm->ParseInfo.iff)
  215.       FreeIFF(ilbm->ParseInfo.iff);
  216.  
  217.     FreeVec(ilbm);
  218.     ilbm= (struct ILBMInfo *)NULL;
  219.   }
  220.  
  221.   return ilbm;
  222. }
  223.  
  224.  
  225. static struct ILBMInfo *myunloadbrush(struct ILBMInfo *ilbm)
  226. {
  227.   if(ilbm)
  228.   {
  229.     unloadbrush(ilbm);
  230.  
  231.     if(ilbm->ParseInfo.iff)
  232.       FreeIFF(ilbm->ParseInfo.iff);
  233.  
  234.     FreeVec(ilbm);
  235.   }
  236.  
  237.   return (struct ILBMInfo *)0;
  238. }
  239.  
  240.  
  241. /**/
  242.  
  243. int main(int argc, char **argv)
  244. {
  245.   struct RDArgs *a;
  246.   LONG args[17] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  247.   int rc= RETURN_OK;
  248.  
  249.   whoami= argv[0]; /* needed by echo() */
  250.  
  251.   if( (a= ReadArgs( /*  0 */ "FROM=NORMAL/K/A,"
  252.                     /*  1 */ "SELECTED/K,"
  253.                     /*  2 */ "IW=ICONWIDTH/K/N,"
  254.                     /*  3 */ "IH=ICONHEIGHT/K/N,"
  255.                     /*  4 */ "MINSIZE/S,"
  256.                     /*  5 */ "TYPE/K,"
  257.                     /*  6 */ "HIGHLIGHT/K,"
  258.                     /*  7 */ "IX=ICONX/K/N,"
  259.                     /*  8 */ "IY=ICONY/K/N,"
  260.                     /*  9 */ "TOOLTYPES/K/M,"
  261.                     /* 10 */ "STACKSIZE/K/N,"
  262.                     /* 11 */ "DEFAULTTOOL/K,"
  263.                     /* 12 */ "WX=WINDOWX/K/N,"
  264.                     /* 13 */ "WY=WINDOWY/K/N,"
  265.                     /* 14 */ "WW=WINDOWWIDTH/K/N,"
  266.                     /* 15 */ "WH=WINDOWHEIGHT/K/N,"
  267.                     /* 16 */ "TO/K/A", args, NULL )) )
  268.   {
  269. #if 0
  270.     printf("NORMAL \"%s\"\n"
  271.            "SELECTED \"%s\"\n"
  272.            "ICONWIDTH=%ld ICONHEIGHT=%ld MINSIZE=%ld\n"
  273.            "TYPE \"%s\"\n"
  274.            "HIGHLIGHT \"%s\"\n"
  275.            "ICONX=%ld ICONY=%ld\n"
  276.            "STACKSIZE=%ld\n"
  277.            "DEFAULTTOOL \"%s\"\n"
  278.            "WINDOWX=%ld WINDOWY=%ld WINDOWWIDTH=%ld WINDOWHEIGHT=%ld\n"
  279.            "TO \"%s\"\n"
  280.       ,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]
  281.       ,args[10],args[11],args[12],args[13],args[14],args[15],args[16]);
  282.     {
  283.       char **t= (char **)(args[9]);
  284.       printf("TOOLTYPES"); while(t && *t) printf(" \"%s\"",*t++); printf("\n");
  285.     }
  286. #endif
  287.  
  288.     /* Open Libraries */
  289.  
  290.     if( (GfxBase = OpenLibrary(GRAPHICSNAME,0)) )
  291.     {
  292.       if( (IconBase= OpenLibrary(ICONNAME,36)) )
  293.       {
  294.         if( (IFFParseBase = OpenLibrary(IFFPARSENAME,0)) )
  295.         {
  296.           struct ILBMInfo *ilbm_normal, *ilbm_selected= (struct ILBMInfo *)NULL;
  297.  
  298.           if( (ilbm_normal= myloadbrush( (char *)(args[0]) )) )
  299.           {
  300.             if(args[1])
  301.             {
  302.               if(!(ilbm_selected= myloadbrush( (char *)(args[1]) )) )
  303.                 rc= RETURN_FAIL;
  304.             }
  305.           }
  306.           else rc= RETURN_FAIL;
  307.  
  308.           /* IW=ICONWIDTH */
  309.  
  310.           if( rc == RETURN_OK )
  311.           {
  312.             WORD width;
  313.  
  314.             if(args[2])
  315.               width= (WORD)(*((LONG *)(args[2])));
  316.  
  317.             else
  318.             {
  319.               if(ilbm_selected)
  320.                  width= args[4] ? MIN(ilbm_normal->Bmhd.w, ilbm_selected->Bmhd.w)
  321.                                 : MAX(ilbm_normal->Bmhd.w, ilbm_selected->Bmhd.w);
  322.               else
  323.                  width= ilbm_normal->Bmhd.w;
  324.             }
  325.  
  326.             icon.do_Gadget.Width = gr.Width = sr.Width = width;
  327.           }
  328.  
  329.           /* IH=ICONHEIGHT */
  330.  
  331.           if( rc == RETURN_OK )
  332.           {
  333.             WORD height;
  334.  
  335.             if(args[3])
  336.               height= (WORD)(*((LONG *)(args[3])));
  337.  
  338.             else
  339.             {
  340.               if(ilbm_selected)
  341.                  height= args[4] ? MIN(ilbm_normal->Bmhd.h, ilbm_selected->Bmhd.h)
  342.                                  : MAX(ilbm_normal->Bmhd.h, ilbm_selected->Bmhd.h);
  343.               else
  344.                  height= ilbm_normal->Bmhd.h;
  345.             }
  346.  
  347.             icon.do_Gadget.Height = gr.Height = sr.Height = height;
  348.           }
  349.  
  350.           /* TYPE */
  351.  
  352.           if( rc == RETURN_OK && args[5] )
  353.           {
  354.             int n= -1;
  355.             char *s= (char *)args[5];
  356.  
  357.                  if( !stricmp(s,"DISK")    )   n= WBDISK;
  358.             else if( !stricmp(s,"DRAWER")  )   n= WBDRAWER;
  359.             else if( !stricmp(s,"TOOL")    )   n= WBTOOL;
  360.             else if( !stricmp(s,"PROJECT") )   n= WBPROJECT;
  361.             else if( !stricmp(s,"GARBAGE") )   n= WBGARBAGE;
  362.             else if( !stricmp(s,"DEVICE")  )   n= WBDEVICE;
  363.             else if( !stricmp(s,"KICK")    )   n= WBKICK;
  364.             else if( !stricmp(s,"APPICON") )   n= WBAPPICON;
  365.  
  366.             if( n < 1 || n > 8 )
  367.             {
  368.               echo("Bad TYPE \"%s\" for template DISK/S,DRAWER/S,TOOL/S,PROJECT/S,GARBAGE/S",s);
  369.               rc= RETURN_ERROR;
  370.             }
  371.             else icon.do_Type= (UBYTE)n;
  372.           }
  373.  
  374.           /* HIGHLIGHT */
  375.  
  376.           if( rc == RETURN_OK && args[6] )
  377.           {
  378.             int n= -1;
  379.             char *s= (char *)args[6];
  380.  
  381.                  if( !stricmp(s,"COMPLEMENT") )   n= GFLG_GADGHCOMP;
  382.             else if( !stricmp(s,"BACKFILL")   )   n= GFLG_GADGHBOX;
  383.             else if( !stricmp(s,"IMAGE")      )   n= GFLG_GADGHIMAGE;
  384.             else if( !stricmp(s,"NONE")       )   n= GFLG_GADGHNONE;
  385.  
  386.             if( n < 0 )
  387.             {
  388.               echo("Bad HIGHLIGHT method \"%s\" for template COMPLEMENT/S,BACKFILL/S,IMAGE/S",s);
  389.               rc= RETURN_ERROR;
  390.             }
  391.             else icon.do_Gadget.Flags= GFLG_GADGIMAGE | (UBYTE)n;
  392.  
  393.             if( ilbm_selected && n != GFLG_GADGHIMAGE )
  394.             {
  395.               echo("SELECTED image `%s' ignored for HIGHLIGHT medthod `%s'",args[1],s);
  396.               ilbm_selected= myunloadbrush(ilbm_selected);
  397.             }
  398.             else if( !ilbm_selected && n == GFLG_GADGHIMAGE )
  399.             {
  400.               echo("You must specify a SELECTED image for HIGHLIGHT method `%s'",s);
  401.               rc= RETURN_ERROR;
  402.             }
  403.           }
  404.  
  405.           /* IX=ICONX */
  406.  
  407.           if( rc == RETURN_OK && args[7] )
  408.           {
  409.             icon.do_Gadget.LeftEdge= (WORD)(*((LONG *)(args[7])));
  410.           }
  411.  
  412.           /* IY=ICONY */
  413.  
  414.           if( rc == RETURN_OK && args[8] )
  415.           {
  416.             icon.do_Gadget.TopEdge= (WORD)(*((LONG *)(args[8])));
  417.           }
  418.  
  419.           /* TOOLTYPES */
  420.  
  421.           if( rc == RETURN_OK && args[9] )
  422.           {
  423.             icon.do_ToolTypes= (char **)(args[9]);
  424.           }
  425.  
  426.           /* STACKSIZE */
  427.  
  428.           if( rc == RETURN_OK && args[10] )
  429.           {
  430.             icon.do_StackSize= (*((LONG *)(args[10])));
  431.           }
  432.  
  433.           /* DEFAULTTOOL */
  434.  
  435.           if( rc == RETURN_OK && args[11] )
  436.           {
  437.             icon.do_DefaultTool= (char *)(args[11]);
  438.           }
  439.  
  440.           /* WX=WINDOWX */
  441.  
  442.           if( rc == RETURN_OK && args[12] )
  443.           {
  444.             dd.dd_NewWindow.LeftEdge= (WORD)(*((LONG *)(args[12])));
  445.           }
  446.  
  447.           /* WY=WINDOWY */
  448.  
  449.           if( rc == RETURN_OK && args[13] )
  450.           {
  451.             dd.dd_NewWindow.TopEdge= (WORD)(*((LONG *)(args[13])));
  452.           }
  453.  
  454.           /* WW=WINDOWWIDTH */
  455.  
  456.           if( rc == RETURN_OK && args[14] )
  457.           {
  458.             dd.dd_NewWindow.Width= (WORD)(*((LONG *)(args[14])));
  459.           }
  460.  
  461.           /* WH=WINDOWHEIGHT */
  462.  
  463.           if( rc == RETURN_OK && args[15] )
  464.           {
  465.             dd.dd_NewWindow.Height= (WORD)(*((LONG *)(args[15])));
  466.           }
  467.  
  468.           /*
  469.            *  Postwork
  470.            */
  471.  
  472.           if( rc == RETURN_OK )
  473.           {
  474.             if(icon.do_Type != WBDRAWER && icon.do_Type != WBDISK)
  475.               icon.do_DrawerData= (struct DrawerData *)NULL;
  476.  
  477.             if(!(icon.do_Gadget.Flags &~ GFLG_GADGHIMAGE))
  478.             {
  479.               icon.do_Gadget.SelectRender= (struct Image *)NULL;
  480.  
  481.               if(ilbm_selected)
  482.                 ilbm_selected= myunloadbrush(ilbm_selected);
  483.             }
  484.             else if(!ilbm_selected)
  485.             {
  486.               icon.do_Gadget.SelectRender= (struct Image *)NULL;
  487.               icon.do_Gadget.Flags= (icon.do_Gadget.Flags & ~GFLG_GADGHIMAGE) | GFLG_GADGHCOMP;
  488.             }
  489.           }
  490.  
  491.           /*
  492.            *  Create the icon and save it
  493.            */
  494.  
  495.           if( rc == RETURN_OK )
  496.           {
  497.             WORD width  = icon.do_Gadget.Width;
  498.             WORD height = icon.do_Gadget.Height;
  499.  
  500.             UWORD *gr_data, *sr_data= (UWORD *)NULL;
  501.  
  502.             if( (gr_data= ImageDataFromBitMap(ilbm_normal->brbitmap, width, height)) )
  503.             {
  504.               UBYTE pp[]= { 0,1,3,7,15,31,63,127,255 };  /* PlanePick lookup table */
  505.  
  506.               gr.ImageData = gr_data;
  507.               gr.Depth     = ilbm_normal->brbitmap->Depth;
  508.               gr.PlanePick = pp[ilbm_normal->brbitmap->Depth];
  509.  
  510.               if(ilbm_selected)
  511.               {
  512.                 if( (sr_data= ImageDataFromBitMap(ilbm_selected->brbitmap, width, height)) )
  513.                 {
  514.                   sr.ImageData = sr_data;
  515.                   sr.Depth     = ilbm_selected->brbitmap->Depth;
  516.                   sr.PlanePick = pp[ilbm_selected->brbitmap->Depth];
  517.                 }
  518.                 else /* !sr_data */
  519.                 {
  520.                   echo("ImageDataFromBitMap() failed -- not enough memory!?");
  521.                   rc= ERROR_NO_FREE_STORE;
  522.                 }
  523.               }
  524.  
  525.               if( rc == RETURN_OK )
  526.               {
  527.                 if( !PutDiskObject((char *)(args[16]),&icon) )
  528.                   PrintFault(rc= IoErr(),(char *)(args[16]));
  529.               }
  530.  
  531.               if(sr_data)
  532.                 FreeVec(sr_data);
  533.  
  534.               FreeVec(gr_data);
  535.             }
  536.             else /* !gr_data */
  537.             {
  538.               echo("ImageDataFromBitMap() failed -- not enough memory!");
  539.               rc= ERROR_NO_FREE_STORE;
  540.             }
  541.           }
  542.  
  543.           ilbm_normal   = myunloadbrush( ilbm_normal   );
  544.           ilbm_selected = myunloadbrush( ilbm_selected );
  545.  
  546.           CloseLibrary(IFFParseBase);
  547.         }
  548.         else
  549.         {
  550.           echo("No %s",IFFPARSENAME);
  551.           rc= RETURN_FAIL;
  552.         }
  553.  
  554.         CloseLibrary(IconBase);
  555.       }
  556.       else
  557.       {
  558.         echo("No %s",ICONNAME);
  559.         rc= RETURN_FAIL;
  560.       }
  561.  
  562.       CloseLibrary(GfxBase);
  563.     }
  564.     else
  565.     {
  566.       echo("No %s",GRAPHICSNAME);
  567.       rc= RETURN_FAIL;
  568.     }
  569.  
  570.     FreeArgs(a);
  571.   }
  572.   else /* !ReadArgs */
  573.   {
  574.     if(argc == 1)
  575.       display_version_information();
  576.  
  577.     else
  578.       PrintFault(rc= IoErr(), NULL);
  579.   }
  580.  
  581.   return rc;
  582. }
  583.  
  584.  
  585.  
  586. /* written 1993 by Tobias Ferber,  All Rights Reserved */
  587.  
  588. UWORD *ImageDataFromBitMap(struct BitMap *bm, WORD width, WORD height)
  589. {
  590.   ULONG bpr = ((width+15)/16) * 2;
  591.   UBYTE *idata= (UBYTE *)AllocVec( bpr * height * bm->Depth, MEMF_CHIP|MEMF_CLEAR );
  592.  
  593.   /*printf("ImageDataFromBitMap(): width=%d,height=%d,depth=%d,bpr=%ld\n",width,height,bm->Depth,bpr);*/
  594.  
  595.   if(idata)
  596.   {
  597.     int p,b,r;
  598.  
  599.     int P= bm->Depth;
  600.     int B= MIN(bm->BytesPerRow, bpr);
  601.     int R= MIN(bm->Rows, height);
  602.  
  603.     for(p=0; p<P; p++)
  604.     {
  605.       UBYTE *src= (UBYTE *)(bm->Planes[p]);
  606.       UBYTE *dst= (UBYTE *)&idata[p*bpr*height];
  607.  
  608.       for(r=0; r<R; r++)
  609.       {
  610.         /* save "beginning of line" values */
  611.         UBYTE *_src= src; 
  612.         UBYTE *_dst= dst;
  613.  
  614.  
  615.         for(b=0; b<B; b++)
  616.           *dst++ = *src++;
  617.  
  618.         /* jump to the next line */
  619.         src= &_src[ bm->BytesPerRow ];
  620.         dst= &_dst[ bpr ];
  621.       }
  622.     }
  623.   }
  624.  
  625.   return (UWORD *)idata;
  626. }
  627.